﻿using Common;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BaseRequest : MonoBehaviour
{
	protected RequestCode requestCode;

	protected ActionCode actionCode;
	protected GameRoot gameRoot { get { return GameRoot.Instance; } }

	Queue<string> queue = new Queue<string>();

	public virtual void Start() {
		gameRoot.AddAction(actionCode, this);
	}

	protected void Update() {
		if (queue.Count > 0) {
			OnResponse(queue.Dequeue());
		}
	}

	public void AddRequest(string data) {
		queue.Enqueue(data);
	}

	/// <summary>
	/// 发送请求的入口
	/// </summary>
	/// <param name="data"></param>
	protected void SendRequest(string data) {
		gameRoot.SendRequest(requestCode, actionCode, data);
	}

	/// <summary>
	/// 接收响应
	/// </summary>
	/// <param name="data"></param>
	public virtual void OnResponse(string data) {
		print(data);
	}

}
